#ifndef MOTOR_H_
#define MOTOR_H_
#include "ieee_robot.h"

//motor.c functions
void init_ccp1(void);
void start_ccp1(void);

//motor.h macro definitions
#if SERVO_BACK == 1
	#define Set_Motor_Reverse()   PORTC = (PORTC | 0x02);\
		                         PORTC = (PORTC & 0xFE)
	#define Set_Motor_Forward()   PORTC = (PORTC | 0x01);\
		                         PORTC = (PORTC & 0xFD)
#elif SERVO_BACK == 0
	#define Set_Motor_Forward()   PORTC = (PORTC | 0x02);\
		                         PORTC = (PORTC & 0xFE)
	#define Set_Motor_Reverse()   PORTC = (PORTC | 0x01);\
		                         PORTC = (PORTC & 0xFD)
#else
	#warning  "No way to drive motors"
#endif

#define Set_Motor_Stop()      PORTC = (PORTC | 0x03)

#define set_duty_ccp1(duty)   CCP1CON = CCP1CON | ((duty & (0x03)) << 4); \
                              CCPR1L = (duty >> 2)

//pwm frequency and duty cycle settings
//#define FREQ_SETTING (unsigned char)49 //20kHz
//#define FREQ_SETTING (unsigned char)249 //4 KHz
#define FREQ_SETTING (unsigned char)124 //2 KHz
#define DUTY_FIFTY 127

//this is the Port C pin that 
//CCP1 pwm is output to
#define PWM_PN 2

//TRIS register of port PWM
//is output to
#define TRIS_PWM TRISC

#endif
